<script type="text/javascript">
	$(document).ready(function() {
		checkReject();
		requestCurrentPagu();
	});
	
	function checkReject()
	{
		var select = document.getElementById("Transaksi_id_status").selectedIndex;
		if (select==1) $('#reject_keterangan').show('slow');
		else $('#reject_keterangan').hide('fast');
	}

	function computeRupiah() 
	{
		var pengali = document.getElementById("kurs_pengali").value;
		document.getElementById("Transaksi_nilai_rupiah").value = document.getElementById("Transaksi_nilai").value * pengali;
	}

	function requestDivisionList()
	{		
		var m_Url = "<?php echo $this->createURL("requestPosList", array("divisi"=>"xdivisix"))?>";
		m_Url = m_Url.replace("xdivisix",document.getElementById("label_divisi").selectedIndex);
	
		//Send ajax request
		$.ajax({
			   	type: "POST",
			   	url: m_Url,
			   	success: function(msg){
					//init
				   var box = document.getElementById("TransaksiOperasi_id_pagu");
				   
				 	//remove all options
				 	var i = box.options.length-1;
				 	for (i;i>=0;i--) box.remove(i);
				 	
				 	//add new options
				 	eval(msg);
					for (var i in retArray)
					{

						var optn = document.createElement("OPTION");
						optn.text = retArray[i];
						optn.value = i;
						box.options.add(optn);
					}

					requestCurrentPagu();
			   }
		});
	}

	function requestCurrentPagu()
	{
		var id_pagu = document.getElementById("TransaksiOperasi_id_pagu").value;
		var m_Url = "<?php echo $this->createURL("requestCurrentPagu", array("id"=>"xidx"))?>";
		m_Url = m_Url.replace("xidx",id_pagu);
	
		//Send ajax request
		$.ajax({
			   	type: "POST",
			   	url: m_Url,
			   	success: function(msg){
			   		if (msg!=null) document.getElementById("label_curr_pagu").value = msg;
			   }
		});
	}
</script>

<div class="form">

<?php 
	//Initialize models
	$transaksi 			= $models['transaksi'];
	$transaksi_atribut 	= $models['transaksi_atribut'];
	$transaksi_operasi	= $models['transaksi_operasi'];
	$transaksi_gagal 	= $models['transaksi_gagal'];

	//Begin form
	$form=$this->beginWidget('CActiveForm', array(
		'id'=>'operasi-form',
		'enableAjaxValidation'=>true,
	)); 
?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary(array($transaksi,$transaksi_atribut,$transaksi_operasi,$transaksi_gagal)); ?>

	<div class="row">
		<?php echo $form->labelEx($transaksi,'pekerjaan'); ?>
		<?php echo $form->textField($transaksi,'pekerjaan',array('size'=>60,'maxlength'=>120)); ?>
		<?php echo $form->error($transaksi,'pekerjaan'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($transaksi,'rekanan'); ?>
		<?php echo $form->textField($transaksi,'rekanan',array('size'=>60,'maxlength'=>60)); ?>
		<?php echo $form->error($transaksi,'rekanan'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($transaksi,'tahap'); ?>
		<?php echo $form->textField($transaksi,'tahap'); ?>
		<?php echo $form->error($transaksi,'tahap'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($transaksi,'periode_awal'); ?>
		<?php 
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
			    'name'=>'Transaksi[periode_awal]',
				'attribute'=>'periode_awal', 
				'value'=>'periode_awal',
          		'model'=>$transaksi,   
			    'options'=>array(
			        'showAnim'=>'fold',
					'dateFormat'=>'yy-mm-dd',
			    ),
			    'htmlOptions'=>array(
			        'style'=>'height:20px;'
			    ),
			));
		?>
		<?php echo $form->error($transaksi,'periode_awal'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($transaksi,'periode_akhir'); ?>
		<?php 
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
			    'name'=>'Transaksi[periode_akhir]',
				'attribute'=>'periode_akhir', 
          		'model'=>$transaksi,   
			    'options'=>array(
			        'showAnim'=>'fold',
					'dateFormat'=>'yy-mm-dd',
			    ),
			    'htmlOptions'=>array(
			        'style'=>'height:20px;',
			    ),
			));
		?>
		<?php echo $form->error($transaksi,'periode_akhir'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($transaksi,'kurs'); ?>
		<?php echo $form->dropDownList($transaksi,'kurs', array('Dollar'=>'Dollar', 'Euro'=>'Euro', 'Yuan'=>'Yuan', 'Rupiah'=>'Rupiah')); ?>
		<?php echo $form->error($transaksi,'kurs'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($transaksi,'nilai'); ?>
		<?php 
			echo $form->textField($transaksi,'nilai'); 
			echo ' dengan kurs satuan Rp '.CHtml::textField('kurs_pengali',1,array('id'=>'kurs_pengali', 'onBlur'=>'computeRupiah();'));
		?>
		<?php echo $form->error($transaksi,'nilai'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($transaksi,'nilai_rupiah'); ?>
		<?php echo $form->textField($transaksi,'nilai_rupiah'); ?>
		<?php echo $form->error($transaksi,'nilai_rupiah'); ?>
	</div>
	
	<br/>

	<div class="row">
		<?php 
			$label_divisi = 'Divisi';
			echo CHtml::label($label_divisi, 'label_divisi');
			echo CHtml::dropDownList($label_divisi, $id, $this->createDivisionList(), array('id'=>'label_divisi', 'onChange'=>'requestDivisionList();'));
		?>
    </div>
    
    <div class="row">
        <?php echo $form->labelEx($transaksi_operasi,'id_pagu'); ?>
        <?php echo $form->dropDownList($transaksi_operasi,'id_pagu', $this->createPosList($id), array('onChange'=>'requestCurrentPagu();')); ?>
        <?php echo $form->error($transaksi_operasi,'id_pagu'); ?>
    </div>
    
    <div class="row">
		<?php 
			$label_curr_pagu = 'Jumlah Anggaran Tersisa';
			echo CHtml::label($label_curr_pagu, 'label_curr_pagu');
			echo CHtml::textField($label_curr_pagu, 0, array('id'=>'label_curr_pagu','disabled'=>'true'));
		?>
    </div>
    
    <br/>
    
    <div class="row">
        <?php echo $form->labelEx($transaksi_operasi,'surat_no'); ?>
        <?php echo $form->textField($transaksi_operasi,'surat_no',array('size'=>25,'maxlength'=>25)); ?>
        <?php echo $form->error($transaksi_operasi,'surat_no'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($transaksi_operasi,'surat_tangggal'); ?>
		<?php 
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
			    'name'=>'Transaksi[surat_tangggal]',
				'attribute'=>'surat_tangggal', 
          		'model'=>$transaksi_operasi,   
			    'options'=>array(
			        'showAnim'=>'fold',
					'dateFormat'=>'yy-mm-dd',
			    ),
			    'htmlOptions'=>array(
			        'style'=>'height:20px;'
			    ),
			));
		?>
        <?php echo $form->error($transaksi_operasi,'surat_tangggal'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($transaksi_operasi,'keterangan'); ?>
        <?php echo $form->textField($transaksi_operasi,'keterangan',array('size'=>60,'maxlength'=>120)); ?>
        <?php echo $form->error($transaksi_operasi,'keterangan'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($transaksi_operasi,'tanda_terima'); ?>
        <?php echo $form->textField($transaksi_operasi,'tanda_terima',array('size'=>60,'maxlength'=>60)); ?>
        <?php echo $form->error($transaksi_operasi,'tanda_terima'); ?>
    </div>
	
	<br/>
	
	<div class="row">
        <?php echo $form->labelEx($transaksi_atribut,'nota_divmum_no'); ?>
        <?php echo $form->textField($transaksi_atribut,'nota_divmum_no',array('size'=>25,'maxlength'=>25)); ?>
        <?php echo $form->error($transaksi_atribut,'nota_divmum_no'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($transaksi_atribut,'nota_divmum_tangggal'); ?>
		<?php 
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
			    'name'=>'TransaksiAtribut[nota_divmum_tangggal]',
				'attribute'=>'nota_divmum_tangggal', 
          		'model'=>$transaksi_atribut,   
			    'options'=>array(
			        'showAnim'=>'fold',
					'dateFormat'=>'yy-mm-dd',
			    ),
			    'htmlOptions'=>array(
			        'style'=>'height:20px;'
			    ),
			));
		?>       
        <?php echo $form->error($transaksi_atribut,'nota_divmum_tangggal'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($transaksi_atribut,'spk_no'); ?>
        <?php echo $form->textField($transaksi_atribut,'spk_no',array('size'=>25,'maxlength'=>25)); ?>
        <?php echo $form->error($transaksi_atribut,'spk_no'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($transaksi_atribut,'spk_tangggal'); ?>
		<?php 
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
			    'name'=>'TransaksiAtribut[spk_tangggal]',
				'attribute'=>'spk_tangggal', 
          		'model'=>$transaksi_atribut,   
			    'options'=>array(
			        'showAnim'=>'fold',
					'dateFormat'=>'yy-mm-dd',
			    ),
			    'htmlOptions'=>array(
			        'style'=>'height:20px;'
			    ),
			));
		?> 
        <?php echo $form->error($transaksi_atribut,'spk_tangggal'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($transaksi_atribut,'po_no'); ?>
        <?php echo $form->textField($transaksi_atribut,'po_no',array('size'=>20,'maxlength'=>20)); ?>
        <?php echo $form->error($transaksi_atribut,'po_no'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($transaksi_atribut,'po_tanggal'); ?>
		<?php 
			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
			    'name'=>'TransaksiAtribut[po_tanggal]',
				'attribute'=>'po_tanggal', 
          		'model'=>$transaksi_atribut,   
			    'options'=>array(
			        'showAnim'=>'fold',
					'dateFormat'=>'yy-mm-dd',
			    ),
			    'htmlOptions'=>array(
			        'style'=>'height:20px;'
			    ),
			));
		?>         
        <?php echo $form->error($transaksi_atribut,'po_tanggal'); ?>
    </div>
    
    <br/>
    
    <div class="row">
		<?php echo $form->labelEx($transaksi,'id_status'); ?>
		<?php echo $form->dropDownList($transaksi,'id_status', array(1=>'Pending',2=>'Rejected',3=>'Approved'), 
				array ('onChange'=>'checkReject();')); ?>
		<?php echo $form->error($transaksi,'id_status'); ?>
	</div>
	
	<div id="reject_keterangan" class="row">
		<?php echo $form->labelEx($transaksi_gagal,'keterangan'); ?>
       	<?php echo $form->textField($transaksi_gagal,'keterangan',array('size'=>60,'maxlength'=>60)); ?>
		<?php echo $form->error($transaksi_gagal,'keterangan'); ?>
	</div>

	<br/>
 
	<div class="row buttons">
		<?php echo CHtml::submitButton($transaksi->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->